package com.esun.payment_api.service.impl;

import com.esun.payment_api.bean.InvContentDetailBean;
import com.esun.payment_api.domain.InvFormContent;
import com.esun.payment_api.domain.InvFormContentExample;
import com.esun.payment_api.mapper.InvFormContentMapper;
import com.esun.payment_api.service.InvFormContentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;

@Service
public class InvFormContentServiceImpl implements InvFormContentService {

    @Resource
    private InvFormContentMapper invFormContentMapper;

    @Override
    public int insert(InvFormContent record) {
        return invFormContentMapper.insertSelective(record);
    }

    @Override
    public int deleteById(BigDecimal id) {
        return invFormContentMapper.deleteById(id);
    }

    @Override
    public int delete(List<BigDecimal> ids) {
        InvFormContent record = new InvFormContent();
        record.setIsDeleted("1");
        InvFormContentExample example = new InvFormContentExample();
        example.createCriteria().andIsDeletedEqualTo("0").andIdIn(ids);
        return invFormContentMapper.updateByExampleSelective(record, example);
    }

    @Override
    public int update(InvFormContent record) {
        return invFormContentMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public InvContentDetailBean getById(BigDecimal id) {
        return invFormContentMapper.getById(id);
    }

//    @Override
//    public List<InvFormContent> getListByInvId(Short invId) {
//        InvFormContent record = new InvFormContent();
//        InvFormContentExample example = new InvFormContentExample();
//        example.createCriteria().andInvIdEqualTo(invId).andIsDeletedEqualTo("0");
//        return invFormContentMapper.selectByExample(example);
//    }

    @Override
    public int insertMultiple(List<InvFormContent> records) {
        int count = 0;
        for (InvFormContent record : records) {
            if (invFormContentMapper.insertSelective(record) > 0) {
                count++;
            } else {
                return -1;
            }
        }
        return count;
    }

    @Override
    public String sumMoneyByInvId(Integer invId) {
        return invFormContentMapper.sumMoneyByInvId(invId);
    }

}
